<template>
  <div>
    <el-button @click="clearJobLog">
      清空日志
    </el-button>
    <el-table :data="list" border style="width: 100%; margin-top: 15px">
      <el-table-column prop="name" label="任务名"></el-table-column>
      <el-table-column prop="createAt" label="完成时间"></el-table-column>
      <el-table-column prop="log" label="日志"></el-table-column>
      <!-- show-overflow-tooltip -->
      <el-table-column prop="status" label="状态">
        <template #default="scope">
          {{ statusList?.[scope.row.status] || "" }}
        </template>
      </el-table-column>
      <el-table-column label="快照">
        <template #default="scope">
          <div style="max-height: 100px; overflow: auto">
            {{ scope.row }}
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script setup>
import { ref } from "vue";
const list = ref([]);
const statusList = ref(["失败", "成功"]);

const emit = defineEmits(["updateConfig"]);
// 获取执行日志列表
const init = async () => {
  const result = await window.pywebview.api.getJobLog();
  if (result.code === 200) {
    list.value = result.data;
  } else {
    ElMessage.error(result.msg);
  }
};
init();
const clearJobLog = async () => {
  const result = await window.pywebview.api.clearJobLog();
  if (result.code === 200) {
    ElMessage.success("清空成功");
    init();
  } else {
    ElMessage.error(result.msg);
  }
};
setInterval(() => {
  init();
}, 1500);
</script>

